<?php
/**
 * Created by PhpStorm.
 * User: Lenovo
 * Date: 2019/4/26
 * Time: 22:06
 */

namespace app\admin\model;
use think\Session;

class Bankcard  extends BaseModel
{
    protected $table='jc_bankcard';
   public function bankindex()
    {
        //获取当前登陆的id
        $uid = Session::get('admin_uid');
        $vip = Guanli::where('id',$uid)->find();
        $arr = User::where('uid',$vip['uid'])->find();
        $rs=$this->alias('bk')
            ->join('jc_user us','us.uid=bk.uid')
            ->order('bk.b_createtime desc')
            ->paginate(7);
        if($arr['daili']==1)
        {
            $rs=$this->alias('bk')
                ->join('jc_user us','us.uid=bk.uid')
                ->where('us.u_path','like','%,'.$arr['uid'].',%')
                ->order('bk.b_createtime desc')
                ->paginate(7);
        }
        if(input('sub')) {
            $where = array();
            $cateid = input('cateid');//下拉菜单
            $key = input('Key');//输入框
            $datemin = input('datemin', '');//最小时间
            $datemax = input('datemax', '');//最大的吧
            if (isset($datemin) && $datemin != '') {
                $where['b_createtime'] = ['>=', $datemin . ' 00:00:00'];
                //dump($where);
            }
            if (isset($datemax) && $datemax != '') {
                $where['b_createtime'] = ['<=', $datemax . ' 23:59:59'];
            }

            if ($cateid == 'u_phone') {
                $where['u_phone'] = ['like', '%' . $key . '%'];
            } else if ($cateid == 'u_name') {
                $where['u_name'] = ['like', '%' . $key . '%'];
            } else if ($cateid == 'b_bank') {
                $where['b_bank'] = ['like', '%' . $key . '%'];
            } else if ($cateid == 'b_card') {
                $where['b_card'] = ['like', '%' . $key . '%'];
            }
            $rs=$this->alias('bk')
                ->join('jc_user us','us.uid=bk.uid')
                ->order('bk.b_createtime desc');
            return $rs=$rs->where($where)->paginate(7,false,['query'=>request()->param()]);
        }
        else
        {
            return $rs;
        }

    }
    //银行卡锁定状态的改变
    public function bankstate()
    {
        $bid=input('bid');
        $cha=$this->where('bid',$bid)->find();
        if($cha['b_state']=='0')
        {
            $state=1;
        }
        else
        {
            $state=0;
        }
        $xiu=$this->where('bid',$bid)->update(['b_state'=>$state]);
        if($xiu)
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }
}